namespace Asmex.FileViewer
{
    using System;
    using System.IO;

    public class OSHeaders : Region
    {
        private Asmex.FileViewer.COFFHeader _coh;
        private long _dataSectionsOffset;
        private Asmex.FileViewer.PEHeader _peh;
        private SectionHeader[] _sech;
        private Asmex.FileViewer.DOSStub _stub;

        public OSHeaders(BinaryReader reader)
        {
            base.Start = 0L;
            this._stub = new Asmex.FileViewer.DOSStub(reader);
            reader.BaseStream.Position = this._stub.PEPos;
            if (reader.ReadUInt32() != 0x4550)
            {
                throw new ModException("File is not a portable executable.");
            }
            this._coh = new Asmex.FileViewer.COFFHeader(reader);
            this._dataSectionsOffset = reader.BaseStream.Position + this._coh.OptionalHeaderSize;
            this._peh = new Asmex.FileViewer.PEHeader(reader);
            reader.BaseStream.Position = this._dataSectionsOffset;
            this._sech = new SectionHeader[this._coh.NumberOfSections];
            for (int i = 0; i < this._sech.Length; i++)
            {
                this._sech[i] = new SectionHeader(reader);
            }
            base.Length = reader.BaseStream.Position;
        }

        public Asmex.FileViewer.COFFHeader COFFHeader
        {
            get
            {
                return this._coh;
            }
        }

        public Asmex.FileViewer.DOSStub DOSStub
        {
            get
            {
                return this._stub;
            }
        }

        public Asmex.FileViewer.PEHeader PEHeader
        {
            get
            {
                return this._peh;
            }
        }

        public SectionHeader[] SectionHeaders
        {
            get
            {
                return this._sech;
            }
        }
    }
}
